package transforms;
import java.util.Iterator;

import org.objectweb.asm.tree.FieldNode;

import com.rshacking.rhf.files.ClassContainer;
import com.rshacking.rhf.updater.Transform;
import com.rshacking.rhf.updater.hooks.ClassHook;
import com.rshacking.rhf.updater.hooks.HooksList;

public class SignLinkTransform extends Transform {

        @Override
        public boolean canActivate(HooksList hooks, ClassContainer cc) {
                return cc.containsFieldType("Ljava/awt/EventQueue;");
        }

        @Override
        public boolean execute(HooksList hooks, ClassContainer cc) {
        	
                ClassHook ch = hooks.add("SignLink", cc.getName());
                Iterator<FieldNode> it = cc.getASM().fields.iterator();
                while (it.hasNext()) {
                        FieldNode fn = it.next();
                        if (fn.desc.equals("Ljava/awt/EventQueue;"))
                                ch.add("eventQueue", fn);
                        else if (fn.desc.equals("Ljava/applet/Applet;")) // TODO fix
                                ch.add("applet", fn);
                }
                return true;
        }

}